home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™94 / Miscellaneous / Randy Thelen / ThreadedSort / AppSpecific / App.cp next >
Encoding:
Text File  |  1994-06-26  |  3.2 KB  |  200 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        App.cp
  3.  
  4.     Contains:    Boilerplate application-specific code.
  5.                 
  6.     Written by: Dave Falkenburg
  7.  
  8.     Copyright:    © 1993-94 by Dave Falkenburg, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.      
  12.  */
  13.  
  14. #include <Windows.h>
  15. #include <Dialogs.h>
  16. #include <Menus.h>
  17. #include <Desk.h>
  18. #include <Errors.h>
  19. #include <Resources.h>
  20. #include <StandardFile.h>
  21.  
  22. #include "AppLib.h"
  23. #include "Window.h"
  24.  
  25. #include "ToolWindow.h"
  26. #include "DocWindow.h"
  27. #include "DialogWindow.h"
  28. #include "MailerWindow.h"
  29. #include "SortPicts.h"
  30.  
  31. #include "MenuBar.h"
  32.  
  33.  
  34. //    Function Prototypes:
  35.  
  36. void    AboutBox(void);
  37. void    OpenExistingDocument(void);
  38.  
  39. OSErr
  40. SetupApplication(void)
  41.     {
  42.     short    prefsRefNum;
  43.     
  44.     prefsRefNum = OpenPreferencesResFile();
  45.     
  46.     SetMenuBar(GetNewMBar(rMenuBar));
  47.     AddResMenu(GetMHandle(mApple),'DRVR');        //    Append Apple Menu Items
  48.  
  49.     TToolWindow    *someTools = new TToolWindow(129);
  50.     TToolWindow    *moreTools = new TToolWindow(130);
  51.         
  52.     InitCursor();
  53.     return (noErr);
  54.     }
  55.  
  56. void
  57. HandleMenu(TWindow * topWindowObj, long menuCode)
  58.     {
  59.     short    menu = (short) (menuCode >> 16);
  60.     short    item = (short) (menuCode & 0xffff);
  61.     Str255    deskAccName;
  62.     
  63.     switch (menu)
  64.         {
  65.         case    mApple:
  66.             switch (item)
  67.                 {
  68.                 case    iAbout:
  69.                     AboutBox();
  70.                     break;
  71.                     
  72.                 default:
  73.                     GetItem(GetMHandle(mApple),item,deskAccName);
  74.                     (void) OpenDeskAcc(deskAccName);
  75.                     break;
  76.                 }
  77.             break;
  78.             
  79.         case    mFile:
  80.             switch (item)
  81.                 {
  82.                 case    iNew:
  83.                     OpenNewDocument();
  84.                     break;
  85.                 
  86.                 case    iOpen:
  87.                     OpenExistingDocument();
  88.                     break;
  89.                 
  90.                 case    iClose:
  91.                     HandleClose(FrontNonFloatingWindow());
  92.                     break;
  93.                     
  94.                 case    iQuit:
  95.                     gDone = true;
  96.                     break;
  97.                     
  98.                 default:
  99.                     break;
  100.                 }
  101.             break;
  102.         
  103.         case    mEdit:
  104.             if ((!SystemEdit(item-1)) && (topWindowObj != nil))
  105.                 {
  106.                 if (topWindowObj->CanEdit())
  107.                     topWindowObj->DoEditMenu(item);
  108.                 }
  109.         
  110.         case    mTest:
  111.             switch(item)
  112.                 {
  113.                 case    iNewDialog:
  114.                     TDialogWindow * aDialog = new TDialogWindow(257);
  115.                     break;
  116.                 
  117.                 default:
  118.                     break;
  119.                 }
  120.             break;
  121.             
  122.         default:
  123.             break;
  124.         }
  125.         
  126.     HiliteMenu(0);
  127.     }
  128.  
  129.  
  130. void
  131. AboutBox(void)
  132.     {
  133.     Handle            versionHandle;
  134.     StringPtr        nullStr = (StringPtr) "\p";
  135.     StringPtr        shortVersionString = nullStr;
  136.     short            itemHit;
  137.     
  138.     versionHandle = GetResource('vers',1);
  139.     if (versionHandle)
  140.         shortVersionString = (StringPtr) ((char *) *versionHandle + 6);
  141.     ParamText(shortVersionString,nullStr,nullStr,nullStr);
  142.     ReleaseResource(versionHandle);
  143.  
  144.     itemHit = StandardAlert(256);
  145.     }
  146.  
  147.  
  148. void
  149. OpenExistingDocument(void)
  150.     {
  151.     StandardFileReply    reply;
  152.     SFTypeList            ourTypes;
  153.     
  154.     Point    where = { -1, -1 };
  155.     
  156.     HiliteWindowsForModalDialog(false);
  157.     CustomGetFile((FileFilterYDUPP) nil, -1, ourTypes, &reply, 0, where,
  158.                   (DlgHookYDUPP) nil,StandardDialogFilterYD, nil,nil,nil);
  159.     HiliteWindowsForModalDialog(true);
  160.     }
  161.  
  162.  
  163. void
  164. ConvertClipboard(void)
  165.     {
  166.     }
  167.  
  168.  
  169. OSErr
  170. OpenNewDocument(void)
  171.     {
  172.     SortPicts    *aNewWindow = new SortPicts();
  173.     
  174.     if (aNewWindow)
  175.         return noErr;
  176.     else
  177.         return memFullErr;
  178.     }
  179.  
  180.  
  181. OSErr
  182. OpenDocument(LetterDescriptor * /* theDocument */)
  183.     {
  184.     return OpenNewDocument();    //    cheat for now…
  185.     }
  186.  
  187.  
  188. OSErr
  189. PrintDocument(LetterDescriptor * /* theDocument */)
  190.     {
  191.     return noErr;
  192.     }
  193.  
  194.  
  195. Boolean
  196. QuitApplication(void)
  197.     {
  198.     return true;
  199.     }
  200.